/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import combinaciones.AlarmaFactory;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.beans.PropertyVetoException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.*;
import negocio.Coordinador;
import negocio.GestorCoordinador;
import negocio.Solicitante;
import negocio.Validaciones.*;
import combinaciones.Problema;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;
import negocio.GestorProblema;
import negocio.Validaciones;
import Validaciones.EstaVacioException;
import Validaciones.NoExisteOperadorExeption;
import Validaciones.NoExisteUserExeption;
import Validaciones.NoesCaracteresException;
import Validaciones.NoesDiezNumeros;
import Validaciones.NoesNumeroExeption;
import Validaciones.NullUserExeption;
import Validaciones.UsuarioexistenteExeption;
import Validaciones.Validacion;
import java.util.logging.Level;
import java.util.logging.Logger;
import negocio.GestorSolicitante;

/**
 *
 * @author INGENIERIA
 */
public class InterfazLlamada extends javax.swing.JInternalFrame {

    DefaultTableModel modelousu = new DefaultTableModel();
    DefaultComboBoxModel modeloTipoCombo = new DefaultComboBoxModel();
    DefaultListModel modeloTipos = new DefaultListModel();
    String nombre = null;
    String cedula = null;
    String contrasenia = null;
    String tipo = null;
    Mensajes mensajes = new Mensajes();
    Calendar Cal = Calendar.getInstance();
    Problema problema = new Problema();
    GestorProblema gestorproblema = new GestorProblema();
    ArrayList listaProb = new ArrayList();
    Coordinador coordinador = new Coordinador();
    boolean operacion = false;
    ArrayList listausu = new ArrayList();
    ArrayList listatipo = new ArrayList();
    Object listaAtributos[] = new Object[5];
    ImageIcon ImgValido = new ImageIcon(getClass().getResource("/Imagenes/CampoValido.jpg"));
    ImageIcon ImgInvalido = new ImageIcon(getClass().getResource("/Imagenes/CampoInvalido.jpg"));
    mipanel bgrTitulo = new mipanel(821, 36, "/imagenes/title_panel1.jpg");
    Validaciones validacedula = new Validaciones();
    DefaultTableModel modeloproblema = new DefaultTableModel();

    public boolean isOperacion() {
        return operacion;
    }

    public void setOperacion(boolean operacion) {
        this.operacion = operacion;
    }

    /**
     * Creates new form IngresoProyecto
     */
    public InterfazLlamada() {
        initComponents();
        pnlMensaje.setVisible(false);
        pnlIngresoFactura.setVisible(false);
        pnlMenu.setVisible(true);
        pnlModificacion.setVisible(true); tabla_problema.setModel(modelousu);
        modelousu.addColumn("estado");
        modelousu.addColumn("cedula");
        modelousu.addColumn("fecha");
        modelousu.addColumn("grado");
        modelousu.addColumn("direccion");
        modelousu.addColumn("descripcion");
        jPanel1.add(bgrTitulo);
        jPanel1.repaint();
        agregarElementos();
        pnlMenu.repaint();
    }

    public void limpiar() {
        int tamanio = modelousu.getRowCount();
        for (int i = 0; i < tamanio; i++) {
            modelousu.removeRow(0);
        }
    }

    public void agregarElementos() {
        limpiar();
        gestorproblema.listar();
        listausu=gestorproblema.getProblemas();
        Iterator it = listausu.iterator();
        while (it.hasNext()) {
            Problema u = (Problema) it.next();
            Object atributosTipo[] = {u.getId(), u.getNombre(), u.getLugar(), u.getMotivo(), u.getNivel(), u.getFecha(), u.getEstado()};
            modelousu.addRow(atributosTipo);

        }
        System.out.println(pnlMenu.getWidth() + " a " + pnlMenu.getHeight());
        System.out.println("Numero:" + modelousu.getRowCount());
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlMensaje = new javax.swing.JPanel();
        lblMensaje = new javax.swing.JLabel();
        btnCerrarMensaje = new javax.swing.JButton();
        lblVerificar = new javax.swing.JLabel();
        pnlMenu = new javax.swing.JPanel();
        btnIngresar = new javax.swing.JButton();
        pnlModificacion = new javax.swing.JPanel();
        pnlGrilla = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabla_problema = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        pnlIngresoFactura = new javax.swing.JPanel();
        txtDireccion = new javax.swing.JTextField();
        lblPorcentajeAvance1 = new javax.swing.JLabel();
        lblProyecto = new javax.swing.JLabel();
        lblCodigo1 = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        btnNuevo = new javax.swing.JButton();
        btnGrabar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        cmbEstado = new javax.swing.JComboBox();
        valcmbCli = new javax.swing.JLabel();
        valDir = new javax.swing.JLabel();
        lblLibro = new javax.swing.JLabel();
        cmbProblema = new javax.swing.JComboBox();
        valcmbPro = new javax.swing.JLabel();
        valNum = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtDescripcion = new javax.swing.JTextField();
        valDes = new javax.swing.JLabel();

        setBackground(new java.awt.Color(250, 249, 242));
        setBorder(null);
        setForeground(new java.awt.Color(255, 255, 102));

        pnlMensaje.setBackground(new java.awt.Color(250, 247, 247));
        pnlMensaje.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblMensaje.setBackground(new java.awt.Color(250, 247, 247));

        btnCerrarMensaje.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cerrar.jpg"))); // NOI18N
        btnCerrarMensaje.setToolTipText("Cerrar Mensaje");
        btnCerrarMensaje.setBorder(null);
        btnCerrarMensaje.setOpaque(false);
        btnCerrarMensaje.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarMensajeActionPerformed(evt);
            }
        });

        lblVerificar.setAutoscrolls(true);

        javax.swing.GroupLayout pnlMensajeLayout = new javax.swing.GroupLayout(pnlMensaje);
        pnlMensaje.setLayout(pnlMensajeLayout);
        pnlMensajeLayout.setHorizontalGroup(
            pnlMensajeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMensajeLayout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addComponent(lblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 393, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblVerificar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(btnCerrarMensaje))
        );
        pnlMensajeLayout.setVerticalGroup(
            pnlMensajeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMensajeLayout.createSequentialGroup()
                .addGroup(pnlMensajeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblMensaje, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblVerificar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCerrarMensaje, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );

        pnlMenu.setBackground(new java.awt.Color(250, 247, 247));
        pnlMenu.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlMenu.setPreferredSize(new java.awt.Dimension(490, 44));

        btnIngresar.setBackground(new java.awt.Color(250, 247, 247));
        btnIngresar.setForeground(new java.awt.Color(255, 255, 255));
        btnIngresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cmd_ingresar.jpg"))); // NOI18N
        btnIngresar.setBorder(null);
        btnIngresar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnIngresar.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
        btnIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIngresarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlMenuLayout = new javax.swing.GroupLayout(pnlMenu);
        pnlMenu.setLayout(pnlMenuLayout);
        pnlMenuLayout.setHorizontalGroup(
            pnlMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMenuLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnIngresar)
                .addGap(178, 178, 178))
        );
        pnlMenuLayout.setVerticalGroup(
            pnlMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMenuLayout.createSequentialGroup()
                .addComponent(btnIngresar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlModificacion.setBackground(new java.awt.Color(250, 247, 247));
        pnlModificacion.setBorder(javax.swing.BorderFactory.createTitledBorder("Lista De Lamadas"));

        pnlGrilla.setBackground(new java.awt.Color(250, 247, 247));

        tabla_problema.setAutoCreateRowSorter(true);
        tabla_problema.setBackground(new java.awt.Color(250, 249, 242));
        tabla_problema.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabla_problema.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Estado", "Cedula solicitante", "fecha", "Grado del problema", "Direccion", "Descripcion"
            }
        ));
        tabla_problema.setColumnSelectionAllowed(true);
        tabla_problema.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tabla_problema.setGridColor(new java.awt.Color(51, 51, 51));
        tabla_problema.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabla_problemaMouseClicked(evt);
            }
        });
        tabla_problema.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                tabla_problemaInputMethodTextChanged(evt);
            }
        });
        tabla_problema.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tabla_problemaPropertyChange(evt);
            }
        });
        tabla_problema.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tabla_problemaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tabla_problemaKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(tabla_problema);

        javax.swing.GroupLayout pnlGrillaLayout = new javax.swing.GroupLayout(pnlGrilla);
        pnlGrilla.setLayout(pnlGrillaLayout);
        pnlGrillaLayout.setHorizontalGroup(
            pnlGrillaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlGrillaLayout.createSequentialGroup()
                .addContainerGap(58, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlGrillaLayout.setVerticalGroup(
            pnlGrillaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlGrillaLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnlModificacionLayout = new javax.swing.GroupLayout(pnlModificacion);
        pnlModificacion.setLayout(pnlModificacionLayout);
        pnlModificacionLayout.setHorizontalGroup(
            pnlModificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlModificacionLayout.createSequentialGroup()
                .addComponent(pnlGrilla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );
        pnlModificacionLayout.setVerticalGroup(
            pnlModificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlGrilla, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jPanel1.setBackground(new java.awt.Color(250, 249, 242));

        jLabel1.setText("LLAMADAS: Ingreso");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlIngresoFactura.setBackground(new java.awt.Color(250, 247, 247));
        pnlIngresoFactura.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Ingreso De Problema"));

        txtDireccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDireccionActionPerformed(evt);
            }
        });
        txtDireccion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDireccionFocusLost(evt);
            }
        });

        lblPorcentajeAvance1.setText("Direccion:");

        lblProyecto.setText("Estado:");

        lblCodigo1.setText("Cedula Solicitante:");

        txtCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCedulaActionPerformed(evt);
            }
        });
        txtCedula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCedulaFocusLost(evt);
            }
        });

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cmd_nuevo.jpg"))); // NOI18N
        btnNuevo.setBorder(null);
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        btnGrabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cmd_grabar.jpg"))); // NOI18N
        btnGrabar.setBorder(null);
        btnGrabar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnGrabarMouseClicked(evt);
            }
        });
        btnGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cmd_cancel.jpg"))); // NOI18N
        btnCancelar.setBorder(null);
        btnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelarMouseClicked(evt);
            }
        });
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        cmbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "propuesto", "aprobado", "incorporado" }));
        cmbEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbEstadoActionPerformed(evt);
            }
        });

        valcmbCli.setBackground(new java.awt.Color(250, 247, 247));
        valcmbCli.setOpaque(true);

        valDir.setBackground(new java.awt.Color(250, 247, 247));
        valDir.setOpaque(true);

        lblLibro.setText("Grado del problema:");

        cmbProblema.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "leve", "regular", "grave" }));
        cmbProblema.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbProblemaActionPerformed(evt);
            }
        });
        cmbProblema.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                cmbProblemaFocusLost(evt);
            }
        });

        valcmbPro.setBackground(new java.awt.Color(250, 247, 247));
        valcmbPro.setOpaque(true);

        valNum.setBackground(new java.awt.Color(250, 247, 247));
        valNum.setOpaque(true);

        jLabel2.setText("Descripcion:");

        valDes.setBackground(new java.awt.Color(250, 247, 247));
        valDes.setOpaque(true);

        javax.swing.GroupLayout pnlIngresoFacturaLayout = new javax.swing.GroupLayout(pnlIngresoFactura);
        pnlIngresoFactura.setLayout(pnlIngresoFacturaLayout);
        pnlIngresoFacturaLayout.setHorizontalGroup(
            pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblProyecto)
                            .addComponent(lblCodigo1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                        .addComponent(btnNuevo)
                        .addGap(18, 18, 18)
                        .addComponent(btnGrabar)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(valcmbCli, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(valNum, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                                .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblPorcentajeAvance1)
                                    .addComponent(lblLibro))
                                .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(cmbProblema, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlIngresoFacturaLayout.createSequentialGroup()
                                        .addGap(9, 9, 9)
                                        .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(48, 48, 48)
                                .addComponent(txtDescripcion)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(valcmbPro, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(valDir, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(valDes, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addComponent(btnCancelar)))
        );
        pnlIngresoFacturaLayout.setVerticalGroup(
            pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlIngresoFacturaLayout.createSequentialGroup()
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(valcmbCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cmbEstado)
                                .addComponent(lblProyecto)))
                        .addGap(18, 18, 18)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblCodigo1)
                            .addComponent(txtCedula)
                            .addComponent(valNum, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnCancelar, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnNuevo, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnGrabar, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(166, 166, 166))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlIngresoFacturaLayout.createSequentialGroup()
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblLibro)
                                .addComponent(cmbProblema, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(valcmbPro, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(valDir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtDireccion, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPorcentajeAvance1, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlIngresoFacturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(txtDescripcion))
                            .addComponent(valDes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(262, 262, 262))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(232, 232, 232)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pnlMenu, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(pnlMensaje, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(39, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlModificacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlIngresoFactura, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(pnlIngresoFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pnlModificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarMensajeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarMensajeActionPerformed
        // TODO add your handling code here:
        lblMensaje.setText("");
        pnlMensaje.setVisible(false);

    }//GEN-LAST:event_btnCerrarMensajeActionPerformed

    private void btnIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIngresarActionPerformed
        // TODO add your handling code here:
        operacion = false;
        pnlIngresoFactura.setVisible(true);
        pnlMenu.setVisible(false);
        pnlModificacion.setVisible(false);
        txtCedula.setEditable(true);
        valDir.setIcon(ImgInvalido);
        valNum.setIcon(ImgInvalido);
        valcmbPro.setIcon(ImgInvalido);
        valDes.setIcon(ImgInvalido);
        valcmbCli.setIcon(ImgInvalido);
        txtCedula.requestFocus();


    }//GEN-LAST:event_btnIngresarActionPerformed

    private void txtDireccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDireccionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDireccionActionPerformed

    private void txtDireccionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDireccionFocusLost
        // TODO add your handling code here:
        try {
            String.valueOf(txtDireccion.getText());
            valDir.setIcon(ImgValido);
        } catch (Exception ex) {
            valDir.setIcon(ImgInvalido);
        }
    }//GEN-LAST:event_txtDireccionFocusLost

    private void txtCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCedulaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCedulaActionPerformed

    private void txtCedulaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCedulaFocusLost
        // TODO add your handling code here:
        try {
            Double.parseDouble(txtCedula.getText());
            valNum.setIcon(ImgValido);
        } catch (Exception ex) {
            valNum.setIcon(ImgInvalido);
        }
    }//GEN-LAST:event_txtCedulaFocusLost

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        // TODO add your handling code here:
        //  limpiaringreso();
        String fecha = "";
        cmbEstado.setSelectedIndex(-1);
        txtCedula.setText(null);
        txtDireccion.setText(null);
        cmbProblema.setSelectedIndex(-1);
        fecha = Cal.get(Cal.YEAR) + "/" + (Cal.get(Cal.MONTH) + 1) + "/" + Cal.get(Cal.DATE);
        valcmbCli.setIcon(ImgInvalido);
        valDir.setIcon(ImgInvalido);
        valNum.setIcon(ImgInvalido);
        valcmbPro.setIcon(ImgInvalido);
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
        lblMensaje.setVisible(true);
        try {
            GuardarLamada();
        } catch (UsuarioexistenteExeption ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (SQLException ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (NullUserExeption ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (NoesDiezNumeros ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (NoesNumeroExeption ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (NoesCaracteresException ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (EstaVacioException ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } catch (NoExisteUserExeption ex) {
            mensajes.mensaje(ex.getMessage(), 2);
        } finally {
        }

    }//GEN-LAST:event_btnGrabarActionPerformed

    private void btnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelarMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarMouseClicked

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        pnlIngresoFactura.setVisible(false);
        agregarElementos();
        btnNuevoActionPerformed(evt);
        pnlModificacion.setVisible(true);
        pnlMenu.setVisible(true);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void cmbEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbEstadoActionPerformed
        // TODO add your handling code here:
        if (operacion == false && cmbEstado.getSelectedIndex() != -1) {
            txtCedula.setEditable(true);
            valcmbCli.setIcon(ImgValido);
        } else if (operacion == true && cmbEstado.getSelectedIndex() != -1) {
            cmbEstado.setEnabled(false);
            txtCedula.setEditable(true);
            valcmbCli.setIcon(ImgValido);
        } else {
            valcmbCli.setIcon(ImgInvalido);
        }

    }//GEN-LAST:event_cmbEstadoActionPerformed

    private void cmbProblemaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbProblemaActionPerformed
        // TODO add your handling code here:
        if (operacion == false && cmbProblema.getSelectedIndex() != -1) {
            txtDireccion.setEditable(true);
            valcmbPro.setIcon(ImgValido);
        } else {
            valcmbPro.setIcon(ImgInvalido);
        }
    }//GEN-LAST:event_cmbProblemaActionPerformed

    private void cmbProblemaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cmbProblemaFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbProblemaFocusLost

    private void tabla_problemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabla_problemaMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_tabla_problemaMouseClicked

    private void tabla_problemaInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tabla_problemaInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_tabla_problemaInputMethodTextChanged

    private void tabla_problemaPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tabla_problemaPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_tabla_problemaPropertyChange

    private void tabla_problemaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabla_problemaKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_tabla_problemaKeyPressed

    private void tabla_problemaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabla_problemaKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_tabla_problemaKeyReleased

    private void btnGrabarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnGrabarMouseClicked
    }//GEN-LAST:event_btnGrabarMouseClicked

    public class mipanel extends javax.swing.JPanel {

        String ruta;

        public mipanel(int ancho, int alto, String ruta) {
            this.setSize(ancho, alto);
            this.ruta = ruta;
        }

        @Override
        public void paint(Graphics g) {

            Dimension tamanio = getSize();
            ImageIcon imagenFondo = new ImageIcon(getClass().getResource(ruta));
            g.drawImage(imagenFondo.getImage(), 0, 0, tamanio.width, tamanio.height, null);
            setOpaque(false);
            super.paintComponent(g);

        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCerrarMensaje;
    private javax.swing.JButton btnGrabar;
    private javax.swing.JButton btnIngresar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JComboBox cmbProblema;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblCodigo1;
    private javax.swing.JLabel lblLibro;
    private javax.swing.JLabel lblMensaje;
    private javax.swing.JLabel lblPorcentajeAvance1;
    private javax.swing.JLabel lblProyecto;
    private javax.swing.JLabel lblVerificar;
    private javax.swing.JPanel pnlGrilla;
    private javax.swing.JPanel pnlIngresoFactura;
    private javax.swing.JPanel pnlMensaje;
    private javax.swing.JPanel pnlMenu;
    private javax.swing.JPanel pnlModificacion;
    private javax.swing.JTable tabla_problema;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JLabel valDes;
    private javax.swing.JLabel valDir;
    private javax.swing.JLabel valNum;
    private javax.swing.JLabel valcmbCli;
    private javax.swing.JLabel valcmbPro;
    // End of variables declaration//GEN-END:variables

    public void GuardarLamada() throws UsuarioexistenteExeption, SQLException, NullUserExeption, NoesDiezNumeros, NoesNumeroExeption, NoesCaracteresException, EstaVacioException, NoExisteUserExeption {

        Validacion validacion = new Validacion();
        int val = 0;
        Calendar Cal = Calendar.getInstance();
        GestorSolicitante gsolicitante = new GestorSolicitante();
        Solicitante solicitante = new Solicitante();
        String fechahora;
        GestorProblema p = new GestorProblema();
        Problema problema = new Problema();

        fechahora = Cal.get(Cal.DATE) + "/" + (Cal.get(Cal.MONTH) + 1) + "/" + Cal.get(Cal.YEAR) + " " + Cal.get(Cal.HOUR_OF_DAY) + ":" + Cal.get(Cal.MINUTE) + ":" + Cal.get(Cal.SECOND);
        ////////////////////asignacion de variables//////////////////////////
        String cedula = txtCedula.getText();
        String direccion = txtDireccion.getText();
        String descripcion = txtDescripcion.getText();
        String est = (String) this.cmbEstado.getSelectedItem();
        int grado = this.cmbProblema.getSelectedIndex() + 1;
        ///////////valida campos////////////////
        validacion.sonLetras(descripcion, "Descripcion");
        validacion.sonNumeros(cedula, "Cedula");
        validacion.vacio(descripcion, "Descripcion");
        validacion.vacio(cedula, "Cedula");
        validacion.vacio(direccion, "Direccion");
        validacion.sonSimbolos(direccion, "Direccion");

        problema.setEstado(est);
        problema.setFecha(fechahora);
        problema.setLugar(direccion);
        problema.setMotivo(descripcion);
        problema.setNivel(String.valueOf(grado));
        problema.setNombre(cedula);
        problema.setId("");

        {
            if (gsolicitante.buscar(cedula) != null) {
                ///////grabar llamada//////////////////
                p.grabar(solicitante, problema);
                lblMensaje.setText("Se guardo Sastifactorimente");;
                AlarmaFactory generador = new AlarmaFactory();
                JOptionPane.showMessageDialog(null, generador.crearAlarma(cmbProblema.getSelectedItem().toString()).notificar());
            } else {
                throw new NoExisteUserExeption("El Solicitante que ingreso no existe.... ");
            }
        }
    }
}
